package com.kingdee.eas.xbang.preparehandle.handle;

import com.kingdee.bos.BOSException;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.xbang.mapping.IOldMPPrepare;
import com.kingdee.eas.xbang.mapping.OldBillTypeEnum;
import com.kingdee.eas.xbang.mapping.OldMPPrepareFactory;
import com.kingdee.eas.xbang.mapping.OldMPPrepareInfo;

/**
 * @author lifetime
 * 
 */
public abstract class HandleUtils {

	public static void prepareHandleFail(String oldID, String prepareID, String errorMsg, String oldBillType) {
		try {
			IOldMPPrepare prepare = OldMPPrepareFactory.getRemoteInstance();
			OldMPPrepareInfo oldMPPrepareInfo = prepare.getOldMPPrepareCollection("where oldID = '" + oldID + "'").get(0);
			if (oldMPPrepareInfo == null) {
				oldMPPrepareInfo = new OldMPPrepareInfo();
				oldMPPrepareInfo.setOldBillType(OldBillTypeEnum.getEnum(oldBillType));
				oldMPPrepareInfo.setOldID(oldID);
				oldMPPrepareInfo.setPrepareID(null);
				oldMPPrepareInfo.setErrorMsg(errorMsg);
				oldMPPrepareInfo.setSucess(false);
			} else {
				oldMPPrepareInfo.setOldBillType(OldBillTypeEnum.getEnum(oldBillType));
				oldMPPrepareInfo.setOldID(oldID);
				oldMPPrepareInfo.setPrepareID(null);
				oldMPPrepareInfo.setErrorMsg(errorMsg);
				oldMPPrepareInfo.setSucess(false);
			}
			prepare.save(oldMPPrepareInfo);
		} catch (BOSException e) {
			e.printStackTrace();
		} catch (EASBizException e) {
			e.printStackTrace();
		}
	}

	public static void prepareHandleSuccess(String oldID, String prepareID, String oldBillType) {
		try {
			IOldMPPrepare prepare = OldMPPrepareFactory.getRemoteInstance();
			OldMPPrepareInfo oldMPPrepareInfo = prepare.getOldMPPrepareCollection("where oldID = '" + oldID + "'").get(0);
			if (oldMPPrepareInfo == null) {
				oldMPPrepareInfo = new OldMPPrepareInfo();
				oldMPPrepareInfo.setOldBillType(OldBillTypeEnum.getEnum(oldBillType));
				oldMPPrepareInfo.setOldID(oldID);
				oldMPPrepareInfo.setPrepareID(prepareID);
				oldMPPrepareInfo.setErrorMsg(null);
				oldMPPrepareInfo.setSucess(true);
			} else {
				oldMPPrepareInfo.setOldBillType(OldBillTypeEnum.getEnum(oldBillType));
				oldMPPrepareInfo.setOldID(oldID);
				oldMPPrepareInfo.setPrepareID(prepareID);
				oldMPPrepareInfo.setErrorMsg(null);
				oldMPPrepareInfo.setSucess(true);
			}
			prepare.save(oldMPPrepareInfo);
		} catch (BOSException e) {
			e.printStackTrace();
		} catch (EASBizException e) {
			e.printStackTrace();
		}
	}

}
